﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LocalizerUtility
{
    /// <summary>
    /// Contains information about node localization 
    /// </summary>
    public class LocalizedData: IComparable
    {
        private int regionId;
        private string data;

        /// <summary>
        /// The class constructor
        /// </summary>
        public LocalizedData()
        {
            regionId = 0;
            data = "";
        }

        /// <summary>
        /// The class constructor
        /// </summary>
        /// <param name="id">A region identificator</param>
        /// <param name="str">A localized string</param>
        public LocalizedData(int id, string str)
        {
            regionId = id;
            data = str;
        }

        /// <summary>
        /// The localized string
        /// </summary>
        public String Data
        {
            get { return data;}
            set { data = value;}
        }

        /// <summary>
        /// Read-only region identificator
        /// </summary>
        public int RegionId
        {
            get { return regionId; }
        }

        /// <summary>
        /// Compares objects
        /// </summary>
        /// <param name="obj">An object to compare with</param>
        /// <returns>0, if objects contain equal data; not 0, otherwise</returns>
        public int CompareTo(object obj)
        {
            if (obj == null)
                return -1;
            LocalizedData locData = null;
            try
            {
                locData = (LocalizedData)obj;
            }
            catch (System.InvalidCastException)
            {
                return -1;
            }
            return data.CompareTo(locData.Data) + regionId.CompareTo(locData.RegionId);
        }

        public override String ToString()
        {
            return "class LocalizedData: { regionId=" + regionId + ", data=\"" + data + "\"}"; 
        }
    }
}
